package com.xdog.web3.exception;

/**
 * Web3 API错误码枚举
 */
public enum Web3ApiError {
    
    // 成功
    SUCCEEDED("0", 200, "Succeeded"),
    
    // 限流相关
    RATE_LIMIT_REACHED("50011", 429, "Rate limit reached. Please refer to API documentation and throttle requests accordingly"),
    
    // 参数相关
    PARAMETER_EMPTY("50014", 400, "Parameter {param0} cannot be empty"),
    PARAMETER_ERROR("51000", 400, "Parameter {param0} error"),
    
    // 系统错误
    SYSTEM_ERROR("50026", 500, "System error. Try again later"),
    
    // 认证相关
    ACCESS_KEY_EMPTY("50103", 401, "Request header \"OK-ACCESS-KEY\" cannot be empty"),
    ACCESS_PASSPHRASE_EMPTY("50104", 401, "Request header \"OK-ACCESS-PASSPHRASE\" cannot be empty"),
    ACCESS_PASSPHRASE_INCORRECT("50105", 401, "Request header \"OK-ACCESS-PASSPHRASE\" incorrect"),
    ACCESS_SIGN_EMPTY("50106", 401, "Request header \"OK-ACCESS-SIGN\" cannot be empty"),
    ACCESS_TIMESTAMP_EMPTY("50107", 401, "Request header \"OK-ACCESS-TIMESTAMP\" cannot be empty"),
    ACCESS_KEY_INVALID("50111", 401, "Invalid OK-ACCESS-KEY"),
    ACCESS_TIMESTAMP_INVALID("50112", 401, "Invalid OK-ACCESS-TIMESTAMP"),
    INVALID_SIGNATURE("50113", 401, "Invalid signature");
    
    private final String code;
    private final int httpStatus;
    private final String message;
    
    Web3ApiError(String code, int httpStatus, String message) {
        this.code = code;
        this.httpStatus = httpStatus;
        this.message = message;
    }
    
    public String getCode() {
        return code;
    }
    
    public int getHttpStatus() {
        return httpStatus;
    }
    
    public String getMessage() {
        return message;
    }
    
    public static Web3ApiError findByCode(String code) {
        for (Web3ApiError error : values()) {
            if (error.code.equals(code)) {
                return error;
            }
        }
        return null;
    }
}